import json

import requests

if __name__ == "__main__":
    # ua伪装
    headers = {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36 Edg/97.0.1072.62"
    }
    ids = []
    details = []
    for page in range(1, 6):
        page = str(page)
        # print("page:", page)
        data = {
            "on": "true",
            "page": page,
            "pageSize": "15",
            "productName": "",
            "conditionType": "1",
            "applyname": "",
            "applysn": ""
        }
        responseJson = requests.post("http://scxk.nmpa.gov.cn:81/xk/itownet/portalAction.do?method=getXkzsList",
                                     headers=headers,
                                     data=data).json()
        for va in responseJson['list']:
            ids.append(va['ID'])

    for id in ids:
        detailJson = requests.post("http://scxk.nmpa.gov.cn:81/xk/itownet/portalAction.do?method=getXkzsById",
                                   headers=headers,
                                   data={
                                       "id": id
                                   }).json()
        details.append(detailJson)
    json.dump(details, open("./file/allData.json", "w", encoding="utf-8"), ensure_ascii=False)
    print("over!!!")
